<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>For Each</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="com.examples.html">« 范例</a></li>
      <li style="float: right;"><a href="com.examples.arrays.html">Arrays and Array-style COM properties »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="com.examples.html">范例</a></li>
    <li>For Each</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="com.examples.foreach" class="section">
  <h2 class="title">For Each</h2>
  <p class="para">
   You may use PHP&#039;s own 
   <a href="control-structures.foreach.html" class="link">foreach</a> statement to iterate
   over the contents of a standard COM/OLE IEnumVariant.  In layman&#039;s terms,
   this means that you can use foreach in places where you would have used
   <code class="literal">For Each</code> in VB/ASP code.
  </p>
  <p class="para">
   <div class="example" id="example-5368">
    <p><strong>示例 #1 For Each in ASP</strong></p>
    <div class="example-contents">
<div class="aspcode"><pre class="aspcode">&lt;%
Set domainObject = GetObject(&quot;WinNT://Domain&quot;)
For Each obj in domainObject
  Response.Write obj.Name &amp; &quot;&lt;br /&gt;&quot;
Next
%&gt;</pre>
</div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-5369">
    <p><strong>示例 #2 foreach in PHP</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;<br />$domainObject&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">COM</span><span style="color: #007700">(</span><span style="color: #DD0000">"WinNT://Domain"</span><span style="color: #007700">);&nbsp;<br />foreach&nbsp;(</span><span style="color: #0000BB">$domainObject&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$obj</span><span style="color: #007700">)&nbsp;{&nbsp;<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">Name&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"&lt;br&nbsp;/&gt;"</span><span style="color: #007700">;&nbsp;<br />}&nbsp;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div></div></div></body></html>